//
//  FiveViewController.m
//  项目二
//
//  Created by rimi on 16/5/13.
//  Copyright © 2016年 objective. All rights reserved.
//

#import "FiveViewController.h"

@interface FiveViewController ()
/**标签*/
@property(nonatomic,strong)UILabel *label;
/**文本框*/
@property(nonatomic,strong)UITextField *textField;

@end

@implementation FiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"文本框、按钮、标签";
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self initUILabelInterface];
    [self initUITextFieldInterface];
    [self initUIButtonInterface];
    [self initUIDiscolorationButtonInterface];
}
-(void)initUILabelInterface{
    /**初始化标签*/
    _label = [[UILabel alloc]initWithFrame:CRM(50, 100, 50, 50)];
    /**设置背景颜色*/
    _label.backgroundColor = [UIColor redColor];
    /**文本显示内容*/
    _label.text = @"123";
    /**对其方式*/
    _label.textAlignment = NSTextAlignmentCenter;
    /**设置字体大小*/
    _label.font = [UIFont systemFontOfSize:18];
    /**设置字体颜色*/
    _label.textColor = [UIColor yellowColor];
    /**显示行数 换行*/
    _label.numberOfLines = 0;
    /**加载到父视图*/
    [self.view addSubview:_label];
}
- (void)initUITextFieldInterface{
    /**初始化文本框*/
    _textField = [[UITextField alloc]initWithFrame:CRM(50, 150, 150, 50)];
    
    /**边框*/
    _textField.borderStyle = UITextBorderStyleRoundedRect;
    
    /**边框颜色*/
    _textField.backgroundColor = [UIColor whiteColor];
    
    /**设置背景*/
    _textField.background = [UIImage imageNamed:@""];
    _textField.disabledBackground = [UIImage imageNamed:@""];
    
    /**设置输入框内容的字体样式和大小*/
//    _textField.font = [UIFont fontWithName:@"Arial" size:20.0f];
    
    /**占位符*/
    _textField.placeholder = @"请输入文本";
    
    /**设置字体颜色*/
//    _textField.textColor = [UIColor redColor];
    
   /** 输入框中是否有个叉号，在什么时候显示，用于一次性删除输入框中的内容*/
    _textField.clearButtonMode = UITextFieldViewModeAlways;
    
    /**每输入一个字符就变成点 用语密码输入*/
    _textField.secureTextEntry = YES;
    
    /**再次编辑就清空*/
    _textField.clearsOnBeginEditing = YES;
    
    /**内容的垂直对齐方式  UITextField继承自UIControl,此类中有一个属性contentVerticalAlignment*/
//    _textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
    
    /**设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动*/
    _textField.adjustsFontSizeToFitWidth = YES;
    
    /**设置键盘的样式*/
    _textField.keyboardType =  UIKeyboardTypeDefault;
    
    /**首字母是否大写*/
//    _textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
    
    /**return键变成什么键*/
//    _textField.returnKeyType =UIReturnKeyDone;
    
    /**键盘外观*/
    _textField.keyboardAppearance=UIKeyboardAppearanceDefault;
    
    //按return键键盘往下收  becomeFirstResponder类要采用UITextFieldDelegate协议_textField.delegate = self;  声明text的代理是我，我会去实现把键盘往下收的方法 这个方法在UITextFieldDelegate里所以我们要采用UITextFieldDelegate这个协议
    /*
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    
    {
        
        [text resignFirstResponder];    //主要是[receiver resignFirstResponder]在哪调用就能把receiver对应的键盘往下收
        
        return YES;
        
    }*/
    [self.view addSubview:_textField];
}
- (void)initUIButtonInterface{
    /**初始化按钮*/
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    
    /**设置按钮的tag值*/
    button.tag = 100;
    
    /**按钮的位置大小*/
    button.frame = CRM(50, 250, 50, 50);
    
    /**按钮的背景颜色*/
    button.backgroundColor = [UIColor redColor];
    
    /**按钮的标题*/
    [button setTitle:@"确定" forState:UIControlStateNormal];
    
    /**设置button填充图片*/
//    button setImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>
//    button setTitleColor:<#(nullable UIColor *)#> forState:<#(UIControlState)#>
//      button setBackgroundImage:<#(nullable UIImage *)#> forState:<#(UIControlState)#>
    
    /**为按钮添加点击事件*/
    [button addTarget:self action:@selector(buttonT:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:button];
}

- (void)initUIDiscolorationButtonInterface{
    /**初始化*/
    UIButton *colorButton = [UIButton buttonWithType:UIButtonTypeCustom];
    /**设置大小*/
    colorButton.bounds = CRM(0, 0, 50, 50);
    /**设置控件中心点的位置*/
    colorButton.center = CPM(CGRectGetMidX(self.view.frame), CGRectGetMidY(self.view.frame)+200);
    [colorButton setTitle:@"变色" forState:UIControlStateNormal];
    colorButton.backgroundColor = [UIColor redColor];
    [colorButton addTarget:self action:@selector(colorbuttonT:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:colorButton];

}
#pragma mark -UIButton
-(void)buttonT:(UIButton *)sender{
    if (_textField.text.length > 0) {
        _label.text = _textField.text;
    }else{
        NSLog(@"请输入一个字符");
    }
    /**回收键盘*/
    [_textField resignFirstResponder];
}
- (void)colorbuttonT:(UIButton *)sender{
    /**改变标签背景颜色*/
    _label.backgroundColor = [UIColor blueColor];
    /**利用 tag 值获取对象*/
    UIButton *currentbutton = [self.view viewWithTag:100];
    currentbutton.backgroundColor = [UIColor blackColor];
}
@end
